#include <iostream>
#include <vector>
using namespace std;
class UFSet {
    vector<int> fa;
    vector<int> size;
public:
    int count;
    UFSet(int n) : fa(n), size(n, 1), count{n} {
        for (int i = 0; i < n; ++i) {
            fa[i] = i;
        }
    }

    bool connect(int a, int b) {
        a = find(a);
        b = find(b);
        if (a == b) return false;
        if (size[a] < size[b]) swap(a, b);
        fa[b] = a;
        size[a] += size[b];
        count--;
        return true;
    }

    int find(int x) {
        if (fa[x] == x) return x;
        return fa[x] = find(fa[x]);
    }

    bool isConnect(int a, int b) {
        return find(a) == find(b);
    }

    void disconnect(int x) {
        fa[x] = x;
    }
};
